package com.taptech.doufu.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.taptech.doufu.R;
import com.taptech.doufu.app.WeMediaApplication;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.umeng.push.PushManager;
import com.taptech.doufu.ui.activity.base.DiaobaoBaseActivity;
import com.taptech.doufu.ui.dialog.PrivacyDialog;
import com.taptech.doufu.util.sp.DiaoBaoSharedPreferences;
import com.umeng.message.UmengNotifyClickActivity;

/**
 * Created by longsiyang on 16/5/19.
 */
public class WelcomeActivity extends UmengNotifyClickActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 解决APK安装后点打开按钮，打开程序后按home键后再通过APP图标唤醒会重新调用oncreate的问题
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
            finish();
            return;
        }
        setContentView(R.layout.activity_welcome);
        Constant.activityRun = true;
        toastPrivacyDialog();
    }


    /**
     * 弹出隐私政策弹框
     * @return
     */
    private void toastPrivacyDialog() {
        boolean showPrivacy = DiaoBaoSharedPreferences.getSharedPreferencesValueToBoolean("privacy_dialog",this,true);
        if (showPrivacy) {
            PrivacyDialog tipDialog = new PrivacyDialog(this, R.style.updateDialog);
            tipDialog.setOnClickListener(new PrivacyDialog.OnClickListener() {
                @Override
                public void onClickSure() {
                    goToMainActivity(true);
                }

                @Override
                public void onClickCancel() {
                    finish();
                }
            });
            tipDialog.show();
        }else{
            goToMainActivity(false);
        }
    }

    private void goToMainActivity(boolean initApp) {
        if (initApp) {
            WeMediaApplication.getInstance().init();
        }
        startActivity(new Intent(this, MainHomeActivity.class));
        finish();
        DiaobaoBaseActivity.exitAnimAlpha(WelcomeActivity.this);
    }

    @Override
    public void onMessage(Intent intent) {
        super.onMessage(intent);
        PushManager.getInstance().handlerMsg(intent);
    }

}
